package com.itheima.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;

//@WebFilter("/*")
public class DemoFilter implements Filter {
    @Override // 请求，执行一次
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("init 初始化执行了");
    }

    @Override // 拦截，执行多次
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("拦截到了请求");

        /**
         * 放行操作（非常重要）
         */
        filterChain.doFilter(servletRequest, servletResponse);
    }

    @Override // 销毁，执行一次
    public void destroy() {
        System.out.println("destroy 销毁执行了");
    }
}
